package utils

import (
	"encoding/json"
	"io/ioutil"
	"zinx/ziface"
)

type GlobalObj struct {
	TcpServer     ziface.IServer //全局server对象
	Host          string         //服务器主机
	TcpPort       int            //当前主机监听端口
	Name          string         //当前主机服务器名称
	Version       string         //版本号
	MaxPacketSize uint32         //数据包最大值
	MaxConn       int            //最大连接数
	WorkerPoolSize	uint32 		//业务工作worker池的数量
	MaxWorkerTaskLen uint32		//业务工作worker对应负责的任务队列最大存储数量
	MaxMsgChanLen uint32 //最大发送缓存 

	ConfFilePath string 
}

var GlobalObject *GlobalObj

func (g *GlobalObj) Reload() {
	data, err := ioutil.ReadFile(g.ConfFilePath)
	if err != nil {
		panic(err)
	}

	err = json.Unmarshal(data, g)
	if err != nil {
		panic(err)
	}
}

func init() {
	GlobalObject = &GlobalObj{
		Name:          "ZinxServerApp",
		Version:       "V0.4",
		TcpPort:       7777,
		Host:          "0.0.0.0",
		MaxConn:       12000,
		MaxPacketSize: 4096,
		ConfFilePath:  "conf/zinx.json",
        WorkerPoolSize: 10,
        MaxWorkerTaskLen: 1024,
        MaxMsgChanLen :1024,
	}

	GlobalObject.Reload()
}
